package com.zfzs.post.modules.transaction.repository;

import com.zfzs.post.modules.transaction.domain.BenefitDay;
import com.zfzs.post.modules.transaction.domain.TransactionInfo;
import com.zfzs.post.modules.transaction.service.dto.BenefitDay4MineDTO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 分润
 *
 * @author wq
 * @date 2019-10-08
 */
public interface BenefitDayRepository extends JpaRepository<BenefitDay, Long>, JpaSpecificationExecutor {

    List<BenefitDay>  findByAgentId(Long agentId);

    @Query(nativeQuery = true,value = "select * from benefit_day where agent_id=:agentId and benefit_date between :startDate and :endDate")
    List<BenefitDay> findByAgentId(Long agentId, String startDate,String endDate);

    @Query(nativeQuery = true,value = "select * from benefit_day where agent_id=?1 and benefit_date=?2")
    BenefitDay findByAgentIdAndDate(Long agentId, String date);

    @Query(nativeQuery = true,value = "select IFNULL(SUM(b.all_benefit),0)  from benefit_day b where b.agent_id in (?1) and b.benefit_date >= ?2 and b.benefit_date <= ?3")
    String getBenefit(List<Long> ids, String startDate, String endDate);
}